package model

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"novel-mgr/app"
)

var err error
var DB *gorm.DB

func Init() {
	Mysql := app.App.Mysql
	dsn := fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8mb4&parseTime=True&loc=Local", Mysql.User, Mysql.Password, Mysql.Host, Mysql.Port, Mysql.Dbname)
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	fmt.Println("连接成功")
	DB.AutoMigrate(&User{}, &Book{})
	fmt.Println("迁移成功")
}
